package com.tsj.spzx.controller;

import com.tsj.spzx.model.dto.system.AssginMenuDto;
import com.tsj.spzx.model.vo.common.Result;
import com.tsj.spzx.model.vo.common.ResultCodeEnum;
import com.tsj.spzx.service.SysRoleMenuService;
import org.junit.jupiter.api.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
@Tag("为角色分配菜单")
@RestController
@RequestMapping("/admin/system/sysRoleMenu")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    /**
     * 1、查询所有菜单
     * 2、根据角色id查询该角色已分配过的菜单 用于回显
     * @param roleId
     * @return
     */
    @GetMapping("/findSysRoleMenuByRoleId/{roleId}")
    public Result<Map<String, Object>> findSysRoleMenuByRoleId(@PathVariable("roleId") Integer roleId){
        Map<String, Object> map = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }

    /**
     * 为角色分配菜单
     * @param assginMenuDto
     * @return
     */
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginMenuDto assginMenuDto){
        sysRoleMenuService.doAssign(assginMenuDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
